#!/usr/bin/env python
#coding:utf-8

import cgi
import cgitb; cgitb.enable()
import re

def httplink(string):
    pattern = '\[(\w+)\]'
    p = re.sub(pattern, r'<a href="\1.wiki">\1</a>', string)
    return p

def title1(string):
    pattern = '=(\w+)='
    p = re.sub(pattern, r'<h2>\1</h2>', string)
    return p

print "Content-type: text/html"
print

print """<html><head><title>text</title></head><body>"""
print "<center>"
print "<h1>欢迎来到我的个人Wiki</h1>"
print """<p><a href="index.py">回到首页</a> | <a href="simple_edit.py">编辑</a></p>"""
print "<hr />"
print "</center>"

f = open("data.dat", "r")
for index in f.readlines():
    print "<p>"
    print title1(httplink(index))
    print "</p>"
print "<br /><hr /><br /><center>WyattWang wwq0327@gmail.com <a href='http://www.python.org'>Python</a>"
print "</body></html>"
